﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Moq;

namespace MoqContrib.AutoMock.Tests.MockGenerators
{
	[TestFixture]
	public class WhenConstructorHasArgs
	{
		#region Types used for testing
		public interface IFoo { }
		public interface IBar { }
		public interface IBaz { }

		public class ClassWithManyConstructors
		{
			public int ArgC = 0;
			public ClassWithManyConstructors(IFoo foo) { ArgC = 1; }
			public ClassWithManyConstructors(IFoo foo, IBar bar) { ArgC = 2; }
			public ClassWithManyConstructors(IFoo foo, IBar bar, IBaz baz) { ArgC = 3; }
		}

		public class ClassWithNoArgs { }
		#endregion

		[Test]
		public void I_use_the_constructor_with_the_most_args()
		{
			var gen = new MockGenerator();
			var result = gen.Generate(typeof(ClassWithManyConstructors));
			Assert.That(result, Is.InstanceOf<Mock<ClassWithManyConstructors>>());
			Assert.That(((ClassWithManyConstructors)result.Object).ArgC, Is.EqualTo(3));
		}

		[Test]
		public void I_can_invoke_a_constructor_with_no_args()
		{
			var gen = new MockGenerator();
			var result = gen.Generate(typeof(ClassWithNoArgs));
			Assert.That(result, Is.InstanceOf<Mock<ClassWithNoArgs>>());
		}

		[Test]
		public void I_can_mock_an_interface()
		{
			var gen = new MockGenerator();
			var result = gen.Generate(typeof(IFoo));
			Assert.That(result, Is.InstanceOf<Mock<IFoo>>());
		}
	}
}
